<?php
  /*
  $Id: domains.php,v 2.0 2004/11/02$
  Released under the GNU General Public License
  Rewritten, Modified And added Whois By Sudhakar Bellamkonda
*/

$tdid = $_REQUEST['tdid'];
// -- webMS Modification --
  // Ensure a valid runtime environment or die
  if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

  // -- webMS Modification --
  // Check if osCommerce environment is already loaded
  if (defined( '_OSCOMMERCE_LOADED' )) {
    if (!DB_SHARED) {
      // Reconnect to osCommerce Database
      tep_db_connect() or die('Unable to connect to database server!');
    }
    // Load osCommerce Globals for Boxes
    global $category_links, $languages_id, $catID, $catID_array, $current_category_id;
    global $request_type, $lng, $cart, $currencies, $language, $navigation, $breadcrumb;
  } else {
    // Load osCommerce Environment for the First Time
    require('components/'.$option.'/includes/application_top.php');
  }
require(DIR_WS_LANGUAGES . $language . '/' . 'register_names.php');
$breadcrumb->add(NAVBAR_TITLE);
?>

<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="3" cellpadding="3">
  <tr>
    
<!-- body_text //-->
<td valign="top">
<br><br>
<table  width="100%"  cellspacing="0" cellpadding="0" >
  <tr>
    <td class="componentheading"><?php echo HEADING_TITLE; ?></td>
    </tr>
</table>
<table border="0" width="100%" cellspacing="0" cellpadding="1" class="infoBox">
  <tr>
    <td>
<table width="100%" border="0" cellpadding="4" cellspacing="4" class="infoBoxContents">
<tr>
  <td class="boxtext" valign="top">
<?php
if (strcmp ($_REQUEST['action'], 'err') != 0)
{
	$domain_query = tep_db_query("SELECT * from ". TABLE_DOMAINS ." where domid = " . $tdid );
	$domain = tep_db_fetch_array($domain_query);
	$dom_id = $domain['domid'];
	$domname = $domain['domain'];
	$available = $domain['avail'];
	$ext = strstr($domname,".");
	$domain_query_price = tep_db_query("SELECT * from ". TABLE_DOMAINS_PRICE ." where tld='" . $ext . "'");
	$dom_price = tep_db_fetch_array($domain_query_price);
	$price = $dom_price['price'];
	$cart_quantity = 2;
}
switch ($_REQUEST['action'])
  {
  	case 'add_to_cart': 
        echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product'));
     	tep_db_query("insert into  " . TABLE_PRODUCTS . " (products_id, products_quantity, products_model, products_image, products_price, products_date_added, products_last_modified, products_date_available, products_weight, products_status, products_tax_class_id, manufacturers_id, products_ordered) values ('', '2', '" . $ext . "', '', '" . $price ."', '', '0', '1', '1', '1', '1', '', '')");
      	$pid= tep_db_insert_id();
       	tep_db_query("insert into " . TABLE_PRODUCTS_DESCRIPTION . "(products_id, language_id, products_name, products_description, products_url, products_viewed) values ('" . $pid . "', '1', '". $domname ."', '" . $ext . "', '', '')");
       	$sprice = '0.000';
       	if(SHOW_GA == 'set'){
       	$sprice = $price;
       	}
       	tep_db_query("INSERT IGNORE INTO `". TABLE_SUBSCRIPTIONS . "` values ('" . $pid . "','Annually',$sprice,'0.000','0','')");
		$products_id = $pid;
		echo '<table  width="100%"  cellspacing="0" cellpadding="0" >' .
		'<tr class=sectiontableheader><td>Domain Name</td><td>Price per Year</td></tr>' . 
		'<tr><td>' . $domname . '</td><td>' . $price . '</td></tr>';
		echo '<tr><td>' . tep_draw_hidden_field('cart_quantity', $cart_quantity) . '</td>';
  	    echo '<td>' .tep_draw_hidden_field('products_id', $products_id) . tep_draw_hidden_field('quantity','1') .'</td></tr>';
		echo '<tr><td colspan=2 align=right>' . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART) . '</td></tr></table>';
	break;
	case 'newcount':
		if ($available == 1)
		{
        	echo tep_draw_form('cart_quantity', tep_href_link('register_names.php', tep_get_all_get_params(array('action')) . 'action=add_to_cart'));
			echo '<font class=boxTextDomains>' . TEXT_INFORMATION_AVAILABLE . '</font>';
	   		echo 'Click on <font color=blue>\'Register\'</font><BR><BR>';
			echo $domname;
	        echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'. tep_image_submit('button_buy_domain.gif', 'Register');
		}
		if ($available == 0)
		{
			echo '<font class=boxTextDomains>' . TEXT_INFORMATION_UNAVAILABLE . '</font>';
			echo '<br><BR>';
			echo '&nbsp;&nbsp;&nbsp;' . $domname . '&nbsp;&nbsp;&nbsp;';
			echo '<a target=_blank href=index2.php?option=com_oscommerce&osMod=checkwhois&domname=' . $domname;
			echo '>Whois</a> ';
			echo '<br>';
		 echo '<a href="' . tep_href_link('domains.php') . '">' . TEXT_SEARCH_AGAIN . '</a>';
		}	
	break;
	case 'err':	
		echo '<table  width="100%"  cellspacing="0" cellpadding="0" >' .
		'<tr><td>' . HEADER_DOM_TLD_ERROR . '</td></tr>' . 
		'<tr><td>' . TEXT_INFORMATION_ERROR . '</td></tr></table>';
		break; 
 }
 ?>
 </form>
</td>
</tr>
</table>
</td>
</tr>
</table> 
<!-- end insert for domain name terms -->

<!-- body_text_eof //-->

  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
<?php
  require(DIR_WS_INCLUDES . 'application_bottom.php');

  // -- webMS Modification --
  // reset the Mambo Database connection (stomped by osCommerce Connection)
  if (!DB_SHARED) {
    global $database, $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix;
    $database = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix );
  }
 ?>
